//
//  welcomeController.swift
//  weibo001
//
//  Created by ios on 15/11/15.
//  Copyright © 2015年 ios. All rights reserved.
//

import UIKit
import SDWebImage

class welcomeController: UIViewController {

    override func loadView() {
        view = backImageView
        
        setupUI()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        print(UserAccountViewModel.sharedUserAccount.avatar)
        iconView.sd_setImageWithURL(UserAccountViewModel.sharedUserAccount.avatar, placeholderImage: UIImage(named: "avatar_default_big"))
    }
   
  // 设置动画
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        iconView.snp_updateConstraints { (make) -> Void in
            make.bottom.equalTo(view.snp_bottom).offset(-view.bounds.height+200)
            
        }
       
        welLabel.alpha = 0
       UIView.animateWithDuration(1.2, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 10, options:[] , animations: { () -> Void in
            //提前更新动画
           self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
            
//            UIView.animateWithDuration(0.8, animations: { () -> Void in
//                self.welLabel.alpha = 1
//            })
        UIView.animateWithDuration(0.8, animations: { () -> Void in
            self.welLabel.alpha = 1
            }, completion: { (_) -> Void in
                //发送通知
                NSNotificationCenter.defaultCenter().postNotificationName(WBSwitchRootViewControllerNotification, object: nil)
                
        })
        }
        
    }
    //edd
    
//懒加载控件
    private lazy var backImageView:UIImageView = UIImageView(image: UIImage(named: "ad_background"))
    
    private lazy var iconView: UIImageView = {
        
        let iv = UIImageView(image: UIImage(named: "avatar_default_big"))
        
        iv.layer.cornerRadius = 45
        iv.layer.masksToBounds = true
        
        return iv
        }()
    
    private lazy var  welLabel:UILabel = UILabel(title: "欢迎杨哥", fontSize: 18)
}


private extension welcomeController {

    func setupUI() {
       //添加视图
    view.addSubview(iconView)
    view.addSubview(welLabel)
    
        //自动布局
        iconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view.snp_centerX)
            make.bottom.equalTo(view.snp_bottom).offset(-200)
            make.width.equalTo(90)
            make.height.equalTo(90)
            
        }
        
        welLabel.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(view.snp_centerX)
            make.top.equalTo(iconView.snp_bottom).offset(16)
            
        }
    
    }

}


